window.onload = initialize;

var clsTagName = "className";
if (window.ActiveXObject)
	clsTagName = "className";
else if (document.getBoxObjectFor)
	clsTagName = "class";

function initialize() {
	var tables = $('table');

	tables.each(function() {

		var clsName = $(this).attr(clsTagName);
		// 表格样式自动填充
			if (clsName.indexOf("activeTable") >= 0) {

				var trs = $(this).find('tr');
				var j = 0;
				// 第一行是标题，不控制
				trs.each(function() {
					if (j++ > 0) {
						var children = $(this).find('td');

						children.each(function() {
							/*
							 * if (j % 2 == 0) { $(this).attr("prevCls",
							 * "table-a"); $(this).attr(clsTagName, "table-a"); }
							 * else { $(this).attr("prevCls", "table-b");
							 * $(this).attr(clsTagName, "table-b"); }
							 */
							var tdContent = $(this).text();
							if (Len(tdContent) > 32) {
								$(this).attr("title", tdContent);
								$(this)
										.text(
												substring(tdContent, 0, 30)
														+ "...");
							}
						});
						/*
						 * $(this).css('cursor', "pointer");
						 * 
						 * $(this).mouseover(function() { var children2 =
						 * $(this).find('td'); children2.each(function() {
						 * $(this).attr(clsTagName, "table-over"); }); });
						 * 
						 * $(this).mouseout( function() { var children2 =
						 * $(this).find('td'); children2.each(function() {
						 * $(this).attr(clsTagName, $(this).attr('prevCls'));
						 * }); }); } });
						 */
			}
		});
			}
	});
}

function Len(str) {
	var i, sum;
	sum = 0;
	for (i = 0; i < str.length; i++) {
		if ((str.charCodeAt(i) >= 0) && (str.charCodeAt(i) <= 255))
			sum = sum + 1;
		else
			sum = sum + 2;
	}
	return sum;
}

function substring(str, from, to) {
	var i, j = 0;
	var rs = "";

	for (i = from; i < to; i++) {
		var s = str.charCodeAt(i);
		if ((s >= 0) && (s <= 255)) {
			rs += str.charAt(j++);
		} else {
			rs += str.charAt(j++);
			i++;
		}
	}
	return rs;
}
 